﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace WPF_MVVM_PathSearchUtil.ViewModels.common
{
    public class BaseCommand<T> : ICommand
    {
        Action<T> action;
        public event EventHandler CanExecuteChanged;

        public bool CanExecute(object parameter)
        {
            return true;
        }

        public void Execute(object parameter)
        {
            if (parameter != null && parameter is T)
            {
                action?.Invoke((T)parameter);
            }
            else
            {
                action?.Invoke(default(T));
            }
        }

        public void SubScribe(Action<T> action)
        {
            this.action = action;
        }
    }

    public class BaseCommand : BaseCommand<object>
    {

    }
}
